# This file tracks dependencies among the files for this paper
# Assume that you'll be in the root directory of the project when you use it

## Macros: This (RCMD) is just a shorter way to write R	--file
## allows replicators to change this for cross-platform use
RCMD = R --no-save --no-restore -f

all: Manuscript/manuscript.pdf

## TODO: cleaning should be recursive
deepclean:
	rm *.pdf *.rda *.done *.Rout

## These are the figures, tables, and output used in both the main body of the
## paper and the appendix.

Manuscript/manuscript.pdf: Manuscript/manuscript.tex \
	Manuscript/abstract.tex \
	Manuscript/body.tex \
	Analysis/supp_desc_new.Rout \
	Manuscript/TorontoAllCommunities1_cropped.pdf \
	Figures_Tables/coefplot_anyDA_new.pdf \
	Figures_Tables/alt_explanations_plot_new.pdf \
	Manuscript/appendix_body.tex \
	Figures_Tables/coefplot_DA_new.pdf \
	Figures_Tables/coefplot_SameDA.pdf \
	Figures_Tables/coefplot_SameDAViewDA.pdf \
	Figures_Tables/coefplot_anyDA_Diversity_new.pdf \
	Figures_Tables/pairwise_plot_social_cohesion_anyDA_new.pdf \
	Figures_Tables/nbmplot_anyDA_new.pdf \
	Figures_Tables/estimation_example_fe.R \
	Figures_Tables/estimation_example_mlm.R \
	Figures_Tables/appendix_xtab_anyDA_new.tex
	cd Manuscript && latexmk -pdf manuscript.tex


# Basic Data Setup
include Makefile.datasetup
## Match across all DAs and all people with perceptions of their local community drawing
include Makefile.design_anyDA_new
## Only match for people who see their DA allow matching across DA
include Makefile.design_DA_new
## Match across all DAs on diversity index and all people with perceptions of their local community drawing
include Makefile.design_anyDA_Diversity_new
## Comparing people living in the same DA who evaluated their own different maps
## AND
## Comparing people living in the same DA who evaluated that same census DA
include Makefile.design_sameDA

##### Alternative explanations and other supplementary analyses. ##############
Analysis/alt_explanations_analysis.rda: Analysis/analysis_anyDA_new.rda \
	Analysis/alt_explanations_analysis.R
	$(RCMD) Analysis/alt_explanations_analysis.R

Figures_Tables/alt_explanations_plot_new.pdf: Analysis/alt_explanations_analysis.rda \
	Figures_Tables/alt_explanations_plot.R
	$(RCMD) Figures_Tables/alt_explanations_plot.R


## Accuracy of those shown their DA
#Analysis/obj_perceptions.Rout: Analysis/obj_perceptions.R \
#	Data/wrkdat_DA0_new.rda
#	$(RCMD) Analysis/obj_perceptions.R > Analysis/obj_perceptions.Rout

## Supplementary Descriptions
Analysis/supp_desc_new.Rout: Analysis/supp_desc_new.R \
	Data/wrkdat_new.rda \
	Data/wrkdatOwnMap_anyDA_new.rda \
	Data/wrkdatOwnMap_new.rda \
	Data/wrkdat_DA0_new.rda \
	Design/matches_anyDA_new.rda \
	Analysis/analysis_anyDA_new.rda \
	Data/big_wrkdat_thin.rda
	$(RCMD) Analysis/supp_desc_new.R > Analysis/supp_desc_new.Rout

############# Visualize the workflow in various ways #########

## or maybe this:
## make -Bnd Manuscript/manuscript.pdf | makefile2graph |  dot -Tpdf -o deps.pdf -Gconcentrate=true -Nstyle=filled -Epenwidth=2

workflow.pdf: Makefile \
	Makefile.datasetup \
	Makefile.design_DA_new \
	Makefile.design_sameDA \
	Makefile.design_anyDA_new \
	Makefile.design_anyDA_Diversity_new \
	make_p_to_json.py json_to_dot.py
	make -qp Manuscript/manuscript.pdf | python3 make_p_to_json.py | python3 json_to_dot.py | dot -Tpdf >| workflow.pdf

workflow.dot: Makefile \
	Makefile.datasetup \
	Makefile.design_DA_new \
	Makefile.design_sameDA \
	Makefile.design_anyDA_new \
	Makefile.design_anyDA_Diversity_new \
	make_p_to_json.py json_to_dot.py
	make -qp | python3 make_p_to_json.py | python3 json_to_dot.py | dot -Txdot >| workflow.dot

workflow.html: Makefile \
	Makefile.datasetup \
	Makefile.design_DA_new \
	Makefile.design_sameDA \
	Makefile.design_anyDA_new \
	Makefile.design_anyDA_Diversity_new
	makefile-graph --highlight --related-only --target Manuscript/manuscript.pdf --format echarts > workflow.html

workflow.txt: Makefile \
	Makefile.datasetup \
	Makefile.design_DA_new \
	Makefile.design_sameDA \
	Makefile.design_anyDA_new \
	Makefile.design_anyDA_Diversity_new
	makefile-graph --highlight --highlight-color lightgreen --related-only --target Manuscript/manuscript.pdf --format tsort > workflow.txt


workflow2.dot: Makefile \
	Makefile.datasetup \
	Makefile.design_DA_new \
	Makefile.design_sameDA \
	Makefile.design_anyDA_new \
	Makefile.design_anyDA_Diversity_new
	makefile-graph --related-only --target Manuscript/manuscript.pdf --format dot > workflow2.dot


